package com.ydcycloud.sys.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.smart.util.StringUtils;

/**
 * <b>Description:基类</b><br>
 * 
 * @author 唐海洋
 * @version 1.0 2016-9-5 下午4:06:30
 */
public class BaseController {

	protected Map<String, Object> resultMap = new HashMap<String, Object>();

	private String[] getAjaxIds(final String str, final String separator) {
		String[] ids = null;
		if (str != null) {
			String[] strs = str.split(separator);
			ids = new String[strs.length];
			for (int i = 0, length = strs.length; i < length; i++) {
				ids[i] = strs[i];
			}
		}
		return ids;
	}

	private Integer[] getAjaxIntegerIds(final String str, final String separator) {
		Integer[] ids = null;
		if (str != null) {
			String[] strs = str.split(separator);
			ids = new Integer[strs.length];
			for (int i = 0, length = strs.length; i < length; i++) {
				ids[i] = Integer.parseInt(strs[i]);
			}
		}
		return ids;
	}

	protected List<String> getAjaxIds(final String id) {
		return StringUtils.isBlank(id) ? new ArrayList<String>(0) : Arrays
				.asList(getAjaxIds(id, ","));
	}

	protected List<Integer> getAjaxIntegerIds(final String id) {
		return id == null ? new ArrayList<Integer>(0) : Arrays
				.asList(getAjaxIntegerIds(id, ","));
	}

	protected String getIdsStr(List<String> idList) {
		String str = "";
		if (idList != null && idList.size() > 0) {
			for (int i = 0; i < idList.size(); i++) {
				if (i == idList.size() - 1) {
					str += "'" + idList.get(i) + "'";
				} else {
					str += "'" + idList.get(i) + "',";
				}
			}

		}
		return str;
	}
}